package user.zc.controller.impl;

import user.zc.config.value.ColumnValue;
import user.zc.controller.ISystemConfig;
import user.zc.service.SystemConfigService;
import user.zc.vo.ColumnDTO;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class SystemConfigController implements ISystemConfig {

    private SystemConfigService systemConfigService = new SystemConfigService();
    @Override
    public List<ColumnDTO> list() throws Exception {
        Map<String, ColumnValue> stringColumnValueMap = systemConfigService.list();
        return stringColumnValueMap.values().stream().map(t->new ColumnDTO(t)).collect(Collectors.toList());
    }

    @Override
    public void saveOrUpdate(ColumnDTO columnDTO) throws Exception {
        systemConfigService.saveOrUpdate(new ColumnValue(columnDTO.getKey(),columnDTO.getType(),columnDTO.getComment(),columnDTO.getLen(),columnDTO.getScale(),columnDTO.getIsPk()));
    }

    @Override
    public void delete(String columnName) throws Exception {
        systemConfigService.delete(columnName);
    }

}
